import pymysql

db=pymysql.connect(host='localhost',
                   user='root',
                   password='123456',
                   database='userlist',
                   charset='utf8mb4')
sql="insert into dictionary (word,mean) values (%s,%s)"
cur=db.cursor()
with open("word.txt",'r',encoding='utf-8') as f:
    for item in f:
        word,mean=item.strip().split("#")[0],item.strip().split("#")[1]
        try:
            cur.execute(sql,[word,mean])
            db.commit()
        except Exception as e:
            print(e)
            db.rollback()

